//
//  WuLiUpLoadImageRequest.m
//  WULIHH
//
//  Created by tang on 16/4/13.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "WuLiUpLoadImageRequest.h"
#import "AFNetworking.h"
#import "Header.h"
#import "UserInfoModel.h"

#import "AFWithToken.h"

@implementation WuLiUpLoadImageRequest


+ (id)UpLoadImage:(NSDictionary *)ImageArray
{
    NSString *string = [NSString stringWithFormat:@"%@%@",@"http://120.76.153.149/v0/", @"work/"];
//    NSDictionary *dic = @{@"source":@"",
//                          @"openId":@"",
//                          @"iconUrl":@"",
//                          @"nickname":@""};
    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    [manager.requestSerializer setValue:[UserInfoModel tokenString] forHTTPHeaderField:@"X-AUTH-TOKEN"];
    [manager.requestSerializer setValue:appVersion forHTTPHeaderField:@"X-APP-VERSON"];
    [manager.requestSerializer setValue:typetext forHTTPHeaderField:@"Content-Type"];

    
//    AFWithToken *manager = [AFWithToken shareInter];
    
    [manager POST:string parameters:ImageArray progress:^(NSProgress * _Nonnull downloadProgress) {
        // 这里可以获取到目前的数据请求的进度
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 请求成功，解析数据
        //        NSLog(@"%@", responseObject);
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        
                [[NSNotificationCenter defaultCenter] postNotificationName:@"uploadsuccess" object:nil userInfo:dic];
        
        NSLog(@"-----------------%@", dic);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 请求失败
        NSLog(@"%@", [error description]);
    }];

    
    return self;
}



@end
